
function specialCheckItemListCtrl($scope, $http, ngDialog, ngDialogProblem) {
  'ngInject';

  this.specialCheckData = {};

  let id = $state.params.id;
  let type = $state.params.type;
  this.id = id;
  this.type = type;

  this.incompletedTask = [];

  // 分页
  this.paginationData = {
    pageNum: 1,
    pageSize: 10,
    taskId: this.id,
    total: '',
  }


  // 获得按钮文字 (可能不需要)
  this.getBtnStatus = () => {
    let status = this.specialCheckData.securityTaskBean.taskStatus;
    switch(status) {
      case 0:
        return '开始检查';
        break;
      case 1:
        return '完成检查';
        break;
      case 2:
        return '完成检查';
        break;
      default:
        return '已完成';
    }
  }

  // 考核项目内、外业的弹框
  this.openItemDetail = function(item) {
    let _this = this;
    ngDialog.open({
      template: 'specialItemDetailDialog',
      className: 'ngdialog-theme-default pa-special-check-item-list-theme',
      scope: $scope,
      controllerAs: 'vm',
      controller: function specialDetailCtrl($http, $scope) {
        'ngInject';

        this.itemDetail1 = angular.copy(item);        

        this.getCheckScore = (score) => {
          switch(score) {
            case 0:
              return '不扣分';
              break;
            default:
              return '-'+score;
          }
        }

        //  获取弹框详情
        this.getItemDetail = () => {

          $http.get(`${SERVER_CONTEXT}/api/securityActivities/app/queryClassifyRelativeItemScoreById/${item.checkClassifyId}/${_this.id}`)
            .then((resp) => {
              if (resp.data.success) {
                this.itemDetailList = resp.data.data;
              } else {
                layer.alert(resp.data.message);
              }
            });

        }

        this.initPage = () => {
          //  获取弹框详情
          this.getItemDetail();
        }

        this.initPage();

      }
    });
  }

  // 提交考核
  this.submitCheck = () => {
    $http.get(`${SERVER_CONTEXT}/api/securityActivities/app/checkCompleted/${id}`
        )
      .then((resp) => {
        if (resp.data.success) {
          layer.msg(resp.data.message);
          $state.reload();
        } else {
          layer.alert(resp.data.message);
        }
      });
  }

  // 内业 待检查 已完成
  // 档案盒数据
  this.documentList = [];

  this.innerList = {};

  // 判断条件跳转到
  this.toCheckItem = (innerItem, toDetailFlag) => {
    // 去打分页面
    if (!toDetailFlag) {
      $state.go('documentItemMgt', {
        id: innerItem.checkClassifyId,
        type: 'check',
        imgUrl: innerItem.src,
        name: innerItem.checkClassifyName,
        taskId: id,
      });
    } else { // 去详情页面
      $state.go('documentInsideDetail', {
        taskId: id,
        innerItemId: innerItem.checkClassifyId,
        imgUrl: innerItem.src,
      });
    }
   
  }

  // 获取专项检查信息
  this.specialInspection = () => {
    let _this = this;
    $http.get(`${SERVER_CONTEXT}/api/securityActivities/app/querySpecialCheckById/${id}`)
      .then((resp) =>{
        _this.specialCheckData = resp.data.data;

        _this.innerList = resp.data.data.checkClassifyList[0].checkClassifyChilds;
        let categoryListCache = _this.innerList
          ,checkedCategoryList = [],uncheckedCategoryList = [];

        // 遍历ajax返回数据,获得14个考核项
        for(let i=0; i<categoryListCache.length; i++){
          let categoryItem = categoryListCache[i];
          let checkCategoryName = categoryItem.checkClassifyName;
          
          categoryItem.src = `book-${categoryItem.checkClassifyId}.png`;
          if (categoryItem.checkClassifyScore) {
            checkedCategoryList.push(categoryItem);
          } else {
            uncheckedCategoryList.push(categoryItem);
          }
        }

        // 未考核完考核项数据加入$scope
        _this.documentList = uncheckedCategoryList;
        // 将原始数据变化为行展示内容
        _this.uncheckedDocumentList4show = _this.getDocumentList4show();

        // 未考核完考核项数据加入$scope
        _this.documentList = checkedCategoryList;
        // 将原始数据变化为行展示内容
        _this.checkedDocumentList4show = _this.getDocumentList4show();
    });
  };

  this.shouldTableShow = false;

  this.loadImage = function(image) {
      return require('../../../assets/images/' + image.src);
  };
  // 处理档案盒数据用于展示
  this.getDocumentList4show= () => {
    let step = 0;
    let index = 0;
    let result = [];
    this.documentList.forEach((item) => {
      if (step%5 == 0) {
        result.push([]);
      }
      index = result.length;
      step++;
      result[index-1].push(item);
    });
    return result;
  };

  this.documentList4show = this.getDocumentList4show();

  // 获取外业综合得分
  this.getTotalScore = (list) => {
    switch(list.checkStatus) {
      case 0:
        return '暂无';
        break;
      case 2:
        return list.checkClassifyScore;
        break;
    }
  }

  // 获取外业问题列表
  this.getProblemList = () => {
    $http.get(`${SERVER_CONTEXT}/api/checkRecord/app/queryContentList/${id}`)
      .then((resp) =>{
        this.specialCheckList = resp.data;
    });
  }

  // 查看内容详情
  this.checkDetail = (id) => {
    ngDialogProblem
      .confirm(id)
      .then((resolve) => {
        this.getProblemList();
      });
  }

  // 初始化页面
  this.initPage = () => {
    // 获取专项检查详细信息
    this.specialInspection();

    // 获取外业问题列表
    this.getProblemList();
  }

  this.initPage();


  // 删除问题详情
  this.deleteProblem = (id) => {
    $scope.modalTitle = '删除问题记录';
    $scope.modalContent = '确认要删除该信息吗?';
    ngDialog.openConfirm({
      template: 'paConfirm',
      className: 'ngdialog-theme-default pa-confirm-theme',
      scope: $scope,
    }).
      then((value) => {
        $http.delete(`${SERVER_CONTEXT}/api/securityActivities/checkProblem/deleteCheckProblem/${id}`)
          .then((resp) => {
            if (resp.data.success) {
              layer.msg(resp.data.message);
              $state.reload(true);
            } else {
              layer.alert(resp.data.message);
            }
          });
      }, (reason) => {});
  }
}

export default specialCheckItemListCtrl;